
***The code used for classifying voting for different party families and classifying electoral winners and losers***

*Data available at https://www.europeansocialsurvey.org/data-portal**

use "ESS1e06_7-ESS2e03_6-ESS3e03_7-ESS4e04_6-ESS5e03_5-ESS6e02_6-ESS7e02_3-ESS8e02_3-ESS9e03_2-ESS10-ESS10SC-ESS11.dta"


***PARTY FAMILIES - Manifesto Project***

*1 - Socialist/Communist
*2 - Social democratic
*3 - Liberal
*4 - Christian Democratic
*5 - Conservative
*6 - Agrarian
*7 - Nationalist
*8 - Ecological/Green
*9 - Ethnic and regional
*10 - Special issue parties
*11 - Electoral alliances of diverse origin without dominant party

generate partyfam=.

*Austria*
replace partyfam = 2 if prtvtat==1 | prtvtaat==1 | prtvtbat==1 | prtvtcat==1 | prtvtdat==1  //SPÖ
replace partyfam = 4 if prtvtat==2 | prtvtaat==2 | prtvtbat==2 | prtvtcat==2 | prtvtdat==2 //ÖVP
replace partyfam = 7 if prtvtat==3 | prtvtaat==3 | prtvtbat==3 | prtvtcat==3 | prtvtdat==3 //FPÖ
replace partyfam = 8 if prtvtat==4 | prtvtaat==5 | prtvtbat==5 | prtvtcat==5 | prtvtdat==5 //Grüne
replace partyfam = 3 if prtvtat==5 | prtvtaat==6  //Liberal Forum
replace partyfam = 7 if prtvtaat==4 | prtvtbat==4  //BZÖ
replace partyfam = 1 if prtvtaat==7 | prtvtbat==6 | prtvtcat==6 | prtvtdat==6 //KPÖ
replace partyfam = 1 if prtvtbat==7 | prtvtcat==7 | prtvtdat==7 //NEOS
replace partyfam = 10 if prtvtbat==8  //Piratenpartei
replace partyfam = 10 if prtvtbat==9  //Team Frank Stronach
replace partyfam = 8 if prtvtcat==4  //PILZ

*Denmark*
replace partyfam = 2 if prtvtdk==1 | prtvtadk==1 | prtvtbdk==1 | prtvtcdk==1 | prtvtddk==1  //Socialdemokratiet (SD)
replace partyfam = 3 if prtvtdk==2 | prtvtadk==2 | prtvtbdk==2 | prtvtcdk==2 | prtvtddk==2 // Det Radikale Venstre (RV)
replace partyfam = 5 if prtvtdk==3 | prtvtadk==3 | prtvtbdk==3 | prtvtcdk==3 | prtvtddk==3 //Det Konservative Folkeparti (KF)
replace partyfam = 5 if prtvtdk==4 | prtvtadk==4  //Centrum-demokraterne (CD)
replace partyfam = 1 if prtvtdk==5 | prtvtadk==5 | prtvtbdk==4 | prtvtcdk==4 | prtvtddk==4 //Socialistisk Folkeparti (SF)
replace partyfam = 7 if prtvtdk==6 | prtvtadk==6 | prtvtbdk==5 | prtvtcdk==5 | prtvtddk==5 //Dansk Folkeparti (DF)
replace partyfam = 4 if prtvtdk==7 | prtvtadk==7 | prtvtbdk==6 | prtvtcdk==6 | prtvtddk==6 //Kristeligt Folkeparti (KF)
replace partyfam = 3 if prtvtdk==8 | prtvtadk==8 | prtvtbdk==7 | prtvtcdk==7 | prtvtddk==7 //Venstre (V)
replace partyfam = 7 if prtvtdk==9 | prtvtadk==9  //Fremskridtspartiet (FP)
replace partyfam = 1 if prtvtdk==10 | prtvtadk==10 | prtvtbdk==9 | prtvtcdk==9 | prtvtddk==9 //Enhedslisten (EL)
replace partyfam = 3 if prtvtbdk==8  //Ny Alliance
replace partyfam = 3 if prtvtcdk==8 | prtvtddk==8  //Liberal Alliance 
replace partyfam = 1 if prtvtddk==10

*Finland*
replace partyfam = 5 if prtvtfi==1 | prtvtafi==1 | prtvtbfi==1 | prtvtcfi==1 | prtvtdfi==1 | prtvtefi==1 | prtvtffi==3 //National Coalition (KK)
replace partyfam = 9 if prtvtfi==2 | prtvtafi==2 | prtvtbfi==2 | prtvtcfi==2 | prtvtdfi==2 | prtvtefi==2 | prtvtffi==4  //Swedish People's Party (RKP/SFP)
replace partyfam = 3 if prtvtfi==3 | prtvtafi==3 | prtvtbfi==3 | prtvtefi==8 | prtvtffi==10   //Liberals
replace partyfam = 6 if prtvtfi==4 | prtvtafi==4 | prtvtbfi==4 | prtvtcfi==3 | prtvtdfi==3 | prtvtefi==3 | prtvtffi==2  //Centre Party (SK)
replace partyfam = 7 if prtvtfi==5 | prtvtafi==5 | prtvtbfi==5 | prtvtcfi==4 | prtvtdfi==4 | prtvtefi==5 | prtvtffi==8  //True Finns (PS)
replace partyfam = 4 if prtvtfi==6 | prtvtafi==6 | prtvtbfi==6 | prtvtcfi==5 | prtvtdfi==5 | prtvtefi==7 | prtvtffi==5  //Christian Democrats (KD)
replace partyfam = 8 if prtvtfi==8 | prtvtafi==7 | prtvtbfi==13 | prtvtcfi==12 | prtvtdfi==10 | prtvtefi==16 | prtvtffi==6  //The Green League
replace partyfam = 2 if prtvtfi==9 | prtvtafi==8 | prtvtbfi==14 | prtvtcfi==13 | prtvtdfi==11 | prtvtefi==17 | prtvtffi==1  //Finnish Social Democratic Party (SSDP)
replace partyfam = 1 if prtvtfi==10 | prtvtafi==9 | prtvtbfi==15 | prtvtcfi==14 | prtvtdfi==12 | prtvtefi==18 | prtvtffi==7 //The Left Alliance 
replace partyfam = 1 if prtvtfi==11 | prtvtafi==10 | prtvtbfi==16 | prtvtcfi==15 | prtvtdfi==13 | prtvtefi==19 //Communist Party of Finland
replace partyfam = 1 if prtvtfi==12 | prtvtafi==11 | prtvtbfi==17 | prtvtcfi==16  //The Communist Workers' Party of Finland
replace partyfam = 1 if prtvtbfi==18  // Workers party
replace partyfam = 7 if prtvtdfi==6  //Freedom party
replace partyfam = 10 if prtvtefi==10 | prtvtffi==10 //Pirate party
replace partyfam = 3 if prtvtffi==16  //Movement Now
replace partyfam = 7 if prtvtffi==21  //Freedom Alliance

*France*
replace partyfam = 3 if prtvtfr==1 | prtvtafr==1 //DL (Démocratie libérale) - Liberal Democracy
replace partyfam = 7 if prtvtfr==3 | prtvtafr==3 | prtvtbfr==2 | prtvtcfr==2 | prtvtdfr==11 | prtvtefr==11 | prtvtffr==8 //Front National (FN) Le Rassemblement national (ex Front National)
replace partyfam = 1 if prtvtfr==4 | prtvtafr==4 | prtvtbfr==3 //LCR (ligue communiste révolutionnaire)
replace partyfam = 1 if prtvtfr==5 | prtvtafr==5 | prtvtbfr==4 | prtvtcfr==5 | prtvtdfr==1 | prtvtefr==1 | prtvtffr==1 //LO (Lutte ouvrière) - Workers' Struggle
replace partyfam = 1 if prtvtfr==6 | prtvtafr==6  //MDC (Mouvement des citoyens)
replace partyfam = 7 if prtvtfr==7 | prtvtafr==7  //MNR (Mouvement National Républicain) - National Republican Movement
replace partyfam = 5 if prtvtfr==8 | prtvtafr==8 | prtvtcfr==8  //MPF (Mouvement pour la France) - Movement for France
replace partyfam = 1 if prtvtfr==9 | prtvtafr==9 | prtvtafr==7 | prtvtdfr==3 | prtvtefr==3 //PC (Parti communiste)
replace partyfam = 2 if prtvtfr==10 | prtvtafr==10 | prtvtafr==8 | prtvtafr==9 | prtvtdfr==5 | prtvtefr==5  //PS (Parti Socialiste)
replace partyfam = 5 if prtvtfr==11 | prtvtafr==11  //RPF (Rassemblement du Peuple Français) Rally of the French People
replace partyfam = 5 if prtvtfr==12 | prtvtafr==12 | prtvtbfr==11 | prtvtafr==10 //RPF (Rassemblement du Peuple Français) Union for the Presidential Majority (UMP)
replace partyfam = 5 if prtvtfr==13 | prtvtafr==13 | prtvtbfr==10  //UDF (Union pour la Démocratie Française - Union for French Democracy
replace partyfam = 8 if prtvtfr==14 | prtvtafr==14 | prtvtbfr==12 | prtvtcfr==12 | prtvtdfr==6 | prtvtefr==6 // Les Verts - The Greens
replace partyfam = 8 if prtvtfr==15 | prtvtafr==15 | prtvtcfr==13  //Autres mouvements écologistes
replace partyfam = 5 if prtvtbfr==6 | prtvtcfr==1  //Nouveau Centre - New Centre
replace partyfam = 1 if prtvtbfr==9 | prtvtcfr==7  //PRG (Parti Radical de Gauche) Left Radical Party
replace partyfam = 3 if prtvtcfr==3  //PR (Parti Radical Valoisien) Radical Party
replace partyfam = 1 if prtvtcfr==4 | prtvtdfr==2 | prtvtefr==2 | prtvtffr==2  //NPA (Nouveau Parti Anti-Capitaliste)
replace partyfam = 1 if prtvtcfr==6 //FDG (Front de Gauche) - Left Front
replace partyfam = 5 if prtvtcfr==11 | prtvtdfr==8 | prtvtefr==8  //MODEM (Mouvement Démocrate)
replace partyfam = 1 if prtvtdfr==4 | prtvtefr==4  //FI (La France Insoumise)
replace partyfam = 3 if prtvtdfr==7 | prtvtefr==7 //LREM (La République en Marche)
replace partyfam = 5 if prtvtdfr==9 | prtvtefr==9 //LR (Les Républicains)
replace partyfam = 7 if prtvtefr==10 | prtvtffr==7 // Debout la France
replace partyfam = 1 if prtvtffr==3  //NUPES
replace partyfam = 1 if prtvtffr==4  // Un candidat divers gauche
replace partyfam = 3 if prtvtffr==5  //Ensemble ! (LREM, MODEM et Horizons) - This is tricky - electoral coalition consisting of centre-right and centre-left parties to support Macron - coded as LIBERAL
replace partyfam = 3 if prtvtffr==6 //Les Républicains et l'UDI
replace partyfam = 7 if prtvtffr==9 //Reconquête ! 

*Germany*
replace partyfam = 2 if prtvde1==1 | prtvade1==1 | prtvbde1==1 | prtvcde1==1 | prtvdde1==1 | prtvede1==2 | prtvfde1==2 | prtvgde1==2  //Social Democratic Party of Germany (SPD)
replace partyfam = 4 if prtvde1==2 | prtvade1==2 | prtvbde1==2 | prtvcde1==2 | prtvdde1==2 | prtvede1==1 | prtvfde1==1 | prtvgde1==1 //Christian Democratic Union/Christian Social Union (CDU/CSU)

replace partyfam = 8 if prtvde1==3 | prtvade1==3 | prtvbde1==3 | prtvcde1==3 | prtvdde1==3 |prtvede1==4 | prtvfde1==4 | prtvgde1==4  //Alliance`90/Greens 

replace partyfam = 3 if prtvde1==4 | prtvade1==4 | prtvbde1==4 | prtvcde1==4 | prtvdde1==4 | prtvede1==5 | prtvfde1==5 | prtvgde1==5  ///Free Democratic Party (FDP)

replace partyfam = 1 if prtvde1==5 | prtvade1==5 | prtvbde1==5 | prtvcde1==5 | prtvdde1==5 | prtvede1==3 | prtvfde1==3 | prtvgde1==3  ///Party of Democratic Socialism (PDS)/The Left. Party of Democratic Socialism

replace partyfam = 7 if prtvde1==6 | prtvade1==6 | prtvbde1==6 | prtvcde1==6 | prtvdde1==6  //Republikaner
replace partyfam = 7 if prtvade1==7 | prtvbde1==7 | prtvcde1==7 | prtvdde1==7 | prtvede1==8  //National Democratic Party
replace partyfam = 10 if prtvdde1==8 | prtvede1==7
replace partyfam = 7 if prtvede1==6 | prtvfde1==6 | prtvgde1==6  //AfD
replace partyfam = 5 if prtvgde1==7  // Free voters

*Greece*
replace partyfam = 2 if prtvtgr==1 | prtvtagr==1 | prtvtbgr==1 | prtvtcgr==1 | prtvtdgr==3 | prtvtegr==3 //PASOK
replace partyfam = 4 if prtvtgr==2 | prtvtagr==2 | prtvtbgr==2 | prtvtcgr==2 | prtvtdgr==1 | prtvtegr==1  //New Democracy
replace partyfam = 1 if prtvtgr==3 | prtvtagr==3 | prtvtbgr==3 | prtvtcgr==3 | prtvtdgr==4 | prtvtegr==4   //Communist Party KKE
replace partyfam = 1 if prtvtgr==4 | prtvtagr==4  //Left Wing Coalition (SYN)
replace partyfam = 1 if prtvtgr==5 | prtvtagr==5   //Democratic Social Movement (DIKKI)
replace partyfam = 7 if prtvtagr==6 | prtvtbgr==5 | prtvtcgr==4   //Popular Orthodox Rally (LAOS)
replace partyfam = 1 if prtvtbgr==4 | prtvtcgr==5 | prtvtdgr==2 | prtvtegr==2  //SYRIZA
replace partyfam = 8 if prtvtbgr==6 | prtvtcgr==7  //Greens
replace partyfam = 7 if prtvtcgr==10 | prtvtdgr==7   //Golden Dawn (XA)
replace partyfam = 7 if prtvtdgr==5 | prtvtegr==5 //Greek Solution
replace partyfam = 1 if prtvtdgr==6  //MeRA25
replace partyfam = 1 if prtvtdgr==8 //Course of Freedom 
replace partyfam = 3 if prtvtdgr==9  // Union of Centrists
replace partyfam = 7 if prtvtegr==6  // Spartans
replace partyfam = 7 if prtvtegr==7  // Niki

*Italy*
replace partyfam = 1 if prtvtit==1  //Democratici di Sinistra (DS) Democrats of the Left
replace partyfam = 3 if prtvtit==2  //La Margherita - Democracy is Freedom – The Daisy
replace partyfam = 1 if prtvtit==3   //Comunisti Italiani - Party of Italian Communists	PdCI
replace partyfam = 8 if prtvtit==4   //Verdi e Sdi - The Girasole (`Sunflower')
replace partyfam = 1 if prtvtit==7   // Rifondazione Comunista - Communist Refoundation Party (PRC) 
replace partyfam = 5 if prtvtit==8 | prtvtcit==8 | prtvtdit==4 | prtvteit==5 //Forza Italia
replace partyfam = 7 if prtvtit==9   // Alleanza Nazionale
replace partyfam = 4 if prtvtit==10   // CCD-CDU (Biancofiore) - White Flower
replace partyfam = 7 if prtvtit==11 | prtvtbit==9 | prtvtdit==3 | prtvteit==4  //Lega Nord
replace partyfam = 1 if prtvtit==12  //Nuovo PSI - New Italian Socialst Party (NPSI)
replace partyfam = 10 if prtvtit==13   //List Di Pietro - Italy of Values
replace partyfam = 10 if prtvtit==14   //Democrazia Europea - DE
replace partyfam = 2 if prtvtbit==1 | prtvtcit==1 | prtvtdit==2 | prtvteit==2 //Democratic Party - Partido Democratico (PD)
replace partyfam = 1 if prtvtbit==2  //Sinistra Ecologia e Libertà (SEL) Left Ecology Freedom	
replace partyfam = 1 if prtvtbit==3  //Rivoluzione Civile - Civil Revolution	(RC)
replace partyfam = 10 if prtvtbit==4 | prtvtcit==7 | prtvtdit==1 | prtvteit==3 //Movimento 5 Stelle - Five Star Movement (M5S)
replace partyfam = 3 if prtvtbit==5  //Scelta Civica - Civic Choice (SC)
replace partyfam = 4 if prtvtbit==6 | prtvtcit==11 | prtvtdit==8  //Union of the Center	UdC)
replace partyfam = 5 if prtvtbit==8  //Popolo delle Libertà (PdL) People of Freedom
replace partyfam = 7 if prtvtbit==10 | prtvtcit==10 | prtvtdit==5 | prtvteit==1 //Fratelli d'Italia - Brothers of Italy
replace partyfam = 3 if prtvtbit==12  //FARE - Giannino - Act to Stop the Decline
replace partyfam = 7 if prtvtbit==13  //La destra - The Right
replace partyfam = 3 if prtvtcit==2 | prtvtdit==7 | prtvteit==8  //+ Europa - More Europe
replace partyfam = 1 if prtvtcit==3 | prtvtdit==11 //Italia Europa Insieme	- Italy Europe Together
replace partyfam = 4 if prtvtcit==4  //Civia Popolare Lorenzin - Popular Civic List (CP)
replace partyfam = 9 if prtvtcit==5 | prtvtdit==14 // SVP-PATT
replace partyfam = 2 if prtvtcit==6 | prtvtdit==6  //Liberi e Uguali - Free and Equal	LeU
replace partyfam = 1 if prtvtcit==12 | prtvtdit==9  //Potere al popolo - Power to the People
replace partyfam = 7 if prtvtcit==13 | prtvtdit==10  //CasaPound
replace partyfam = 2 if prtvtdit==31 //Altro
replace partyfam = 3 if prtvteit==6 //Terzo Polo (Azione -Italia Viva)
replace partyfam = 8 if prtvteit==7

*Netherlands*
replace partyfam = 4 if prtvtnl==1 | prtvtanl==1 | prtvtbnl==1 | prtvtcnl==1 | prtvtdnl==4 | prtvtenl==4 | prtvtfnl==5 | prtvtgnl==5 | prtvthnl==5 | prtvtinl==5 //Christian Democratic Party
replace partyfam = 2 if prtvtnl==2 | prtvtanl==2 | prtvtbnl==2 | prtvtcnl==2 | prtvtdnl==2 | prtvtenl==2 | prtvtfnl==2 | prtvtgnl==2 | prtvthnl==2 | prtvtinl==2  //Labour Party
replace partyfam = 3 if prtvtnl==3 | prtvtanl==3 | prtvtbnl==3 | prtvtcnl==3 | prtvtdnl==1 | prtvtenl==1 | prtvtfnl==1 | prtvtgnl==1 | prtvthnl==1 | prtvtinl==1 //Party for Freedom and Democracy VVD
replace partyfam = 7 if prtvtnl==4 | prtvtanl==4 | prtvtbnl==4 | prtvtcnl==4 //List Pim Fortuyn
replace partyfam = 3 if prtvtnl==5 | prtvtanl==5 | prtvtbnl==5 | prtvtcnl==5 | prtvtdnl==6 | prtvtenl==6 | prtvtfnl==6 | prtvtgnl==6 | prtvthnl==6 | prtvtinl==6 //Democrats'66
replace partyfam = 8 if prtvtnl==6 | prtvtanl==6 | prtvtbnl==6 | prtvtcnl==6 | prtvtdnl==7 | prtvtenl==7 | prtvtfnl==8 | prtvtgnl==8 | prtvthnl==8 | prtvtinl==8  //Green Left
replace partyfam = 1 if prtvtnl==7 | prtvtanl==7 | prtvtbnl==7 | prtvtcnl==7 | prtvtdnl==5 | prtvtenl==5 | prtvtfnl==4 | prtvtgnl==4 | prtvthnl==4 | prtvtinl==4 //Socialist Party
replace partyfam = 4 if prtvtnl==8 | prtvtanl==8 | prtvtbnl==8 | prtvtcnl==8 | prtvtdnl==8 | prtvtenl==8 | prtvtfnl==7 | prtvtgnl==7 | prtvthnl==7 | prtvtinl==7 //Christian Union
replace partyfam = 3 if prtvtnl==9 | prtvtanl==9 | prtvtbnl==9 | prtvtcnl==9 //Liveable Netherlands
replace partyfam = 10 if prtvtanl==10 | prtvtbnl==10 | prtvtcnl==10 | prtvtdnl==9 | prtvtenl==9 | prtvtfnl==9 | prtvtgnl==9 | prtvthnl==9 | prtvtinl==9 //Political Reformed Party
replace partyfam = 10 if prtvtanl==11 | prtvtcnl==12 | prtvtdnl==10 | prtvtenl==10 | prtvtfnl==10 | prtvtgnl==10 | prtvthnl==10  | prtvtinl==10 //Party for the animals
replace partyfam = 7 if prtvtcnl==11 | prtvtdnl==3 | prtvtenl==3 | prtvtfnl==3 | prtvtgnl==3 | prtvthnl==3 | prtvtinl==3 //PVV
replace partyfam = 10 if prtvtenl==11  //Pirate Party 
replace partyfam = 10 if prtvtenl==12 | prtvtfnl==11 | prtvtgnl==11 | prtvthnl==11 | prtvtinl==11 //50+
replace partyfam = 2 if prtvtgnl==12 | prtvthnl==12 | prtvtinl==12  //DENK
replace partyfam = 7 if prtvtgnl==13 | prtvthnl==13 | prtvtinl==13  //Forum for Democracy
replace partyfam = 1 if prtvthnl==14 | prtvtinl==14 //Article 1 - BIJ1
replace partyfam = 3 if prtvthnl==15 | prtvtinl==15 //Volt
replace partyfam = 7 if prtvthnl==16 | prtvtinl==16 //JA21
replace partyfam = 6 if prtvthnl==17 | prtvtinl==17 //  BoerBurgerBeweging

*Norway*
replace partyfam = 1 if prtvtno==1 | prtvtano==1 | prtvtbno==1 | prtvtbno==1 | prtvtcno==1 //rød valgallianse (RV), Rødt (R)
replace partyfam = 1 if prtvtno==2 | prtvtano==2 | prtvtbno==2 | prtvtbno==2  | prtvtcno==2 //socialistisk venstreparti (SV)
replace partyfam = 2 if prtvtno==3 | prtvtano==3 | prtvtbno==3 | prtvtbno==3 | prtvtcno==3 //arbeiderpartiet (AP)
replace partyfam = 3 if prtvtno==4 | prtvtano==4 | prtvtbno==4 | prtvtbno==4 | prtvtcno==4 //venstre (V)
replace partyfam = 4 if prtvtno==5 | prtvtano==5 | prtvtbno==5 | prtvtbno==5 | prtvtcno==5 //kristelig folkeparti (KrF)
replace partyfam = 6 if prtvtno==6 | prtvtano==6 | prtvtbno==6 | prtvtbno==6 | prtvtcno==6  //senterpartiet (Sp)
replace partyfam = 5 if prtvtno==7 | prtvtano==7 | prtvtbno==7 | prtvtbno==7 | prtvtcno==7 //høyre (H)
replace partyfam = 7 if prtvtno==8 | prtvtano==8 | prtvtbno==8 | prtvtbno==8 | prtvtcno==8 //fremskrittspartiet (FrP)
replace partyfam = 10 if prtvtno==9 | prtvtano==9 | prtvtbno==9  //kystpartiet
replace partyfam = 8 if prtvtbno==10 | prtvtbno==10 | prtvtcno==9 //miljøpartiet de grønne (MdG)

*Portugal*
replace partyfam = 1 if prtvtpt==1 | prtvtapt==1 | prtvtbpt==1 | prtvtdpt==2 | prtvtept==3 //BE -  Bloco de Esquerda - Left Bloc
replace partyfam = 4 if prtvtpt==2 | prtvtapt==2 | prtvtbpt==2 | prtvtdpt==3 | prtvtept==4 //CDS/PP - Centro Democrático Social -Social Democratic Center-Popular Party [CHR enligt Manifesto]
replace partyfam = 1 if prtvtpt==5 | prtvtapt==3 | prtvtept==14 | prtvtept==15 //PCP/PEV - Partido Comunista Português - Portuguese Communist Party
replace partyfam = 1 if prtvtpt==6 | prtvtapt==4 | prtvtbpt==4 //PCTP/MRPP - Partido Comunista dos Traba
replace partyfam = 2 if prtvtpt==10 | prtvtapt==11 | prtvtbpt==11 | prtvtdpt==18 | prtvtept==18 //PS - Partido Socialista
replace partyfam = 5 if prtvtpt==11 | prtvtapt==10 | prtvtbpt==10 | prtvtdpt==16 | prtvtept==16 //PSD - Partido Social Democrata [CON enligt Manifesto]
replace partyfam = 1 if prtvtbpt==3 | prtvtdpt==12  //CDU Unified Democratic Coalition
replace partyfam = 7 if prtvtdpt==4 | prtvtept==5 //Chega
replace partyfam = 9 if prtvtdpt==11 | prtvtept==13 //PAN
replace partyfam = 3 if prtvtept==7 //IL Liberal initiative
replace partyfam = 8 if prtvtept==9 //L - Livre

*Spain*
replace partyfam = 5 if prtvtes==1 | prtvtaes==1 | prtvtbes==1 | prtvtces==1 | prtvtdes==1 | prtvtees==1 | prtvtfes==2 | prtvtges==1 //Partido Popular (PP)
replace partyfam = 2 if prtvtes==2 | prtvtaes==2 | prtvtbes==2 | prtvtces==2 | prtvtdes==2 | prtvtees==2 | prtvtfes==1   | prtvtges==2  //Partido Socialista Obrero Español (PSOE)
replace partyfam = 1 if prtvtes==3 | prtvtaes==3 | prtvtbes==3 | prtvtces==4    //Izquierda Unida (IU)
replace partyfam = 9 if prtvtes==4 | prtvtaes==4 | prtvtbes==4 | prtvtces==3   //Convergència i Unió (CiU)
replace partyfam = 9 if prtvtes==5 | prtvtaes==5 | prtvtbes==5 | prtvtces==8 | prtvtces==10 | prtvtees==10 | prtvtfes==8 | prtvtges==5 //Esquerra Repubicana de Catalunya (ERC)
replace partyfam = 9 if prtvtes==6 | prtvtaes==6   //Iniciativa per Catalunya-Verds (ICV)
replace partyfam = 9 if prtvtes==7 | prtvtaes==7 | prtvtbes==6 | prtvtces==7   ///Partido Nacionalista Vasco (PNV)

replace partyfam = 9 if prtvtes==8 | prtvtaes==8   //Eusko Alkartasuna (EA)
replace partyfam = 9 if prtvtes==9 | prtvtaes==9 | prtvtbes==7 | prtvtces==9 | prtvtees==12 | prtvtfes==16 | prtvtges==9 //Bloque Nacionalista Galego (BNG)
replace partyfam = 9 if prtvtes==10 | prtvtaes==10 | prtvtbes==8 | prtvtces==10 | prtvtces==15 | prtvtees==15 | prtvtfes==13 //Coalición Canaria (CC)
replace partyfam = 9 if prtvtes==11 | prtvtaes==11   //Partido Andalucista (PA)
replace partyfam = 9 if prtvtes==12 | prtvtaes==12   //Chunta Aragonesista (CHA)
replace partyfam = 3 if prtvtbes==10 | prtvtces==6 //Unión Progreso y Democracia (UPyD)
replace partyfam = 10 if prtvtces==5   //AMAIUR
replace partyfam = 9 if prtvtces==11 | prtvtces==8 | prtvtees==9 | prtvtees==9 | prtvtfes==15 //Compromís - EQUO
replace partyfam = 1 if prtvtces==3 | prtvtees==3 | prtvtfes==4 | prtvtges==4 //Podemos/SUMAR
replace partyfam = 3 if prtvtces==5 | prtvtees==5 | prtvtfes==6  //Ciudadanos (Citizens)
replace partyfam = 9 if prtvtces==7 | prtvtees==7 | prtvtfes==5  //En Comú Podem - In common we can
replace partyfam = 9 if prtvtces==11 | prtvtees==11  //CDC-PdeCAT
replace partyfam = 9 if prtvtces==12   ///En Marea

replace partyfam = 9 if prtvtces==13 | prtvtees==13 | prtvtfes==11 | prtvtges==8 //EAJ-PNV (Basque national party)
replace partyfam = 9 if prtvtces==14 | prtvtees==14 | prtvtfes==12 | prtvtges==7  // EH Bildu
replace partyfam = 10 if prtvtces==18 | prtvtees==18 | prtvtges==12  //pacma
replace partyfam = 1 if prtvtees==8 | prtvtfes==7 //Más País
replace partyfam = 7 if prtvtees==16 | prtvtfes==3 | prtvtges==3 //VOX
replace partyfam = 3 if prtvtees==17 | prtvtfes==14 //Navarra Suma
replace partyfam = 9 if prtvtees==19 | prtvtfes==9 //CUP Popular Unity Candidacy
replace partyfam = 9 if prtvtees==20 | prtvtfes==17  //PRC
replace partyfam = 9 if prtvtfes==9 | prtvtges==6 //Junts x Cat
replace partyfam = 9 if prtvtfes==18 //Teruel existe
replace partyfam = 9 if prtvtges==11 //UPN

*Sweden*
replace partyfam = 6 if prtvtse==1 | prtvtase==1 | prtvtbse==1 | prtvtcse==1 | prtvtdse==1 //centerpartiet
replace partyfam = 3 if prtvtse==2 | prtvtase==2 | prtvtbse==2 | prtvtcse==2 | prtvtdse==3 //folkpartiet-lib
replace partyfam = 4 if prtvtse==3 | prtvtase==3 | prtvtbse==3 | prtvtcse==3 | prtvtdse==2 //kristdemokraterna
replace partyfam = 8 if prtvtse==4 | prtvtase==4 | prtvtbse==4 | prtvtcse==4 | prtvtdse==4  //miljöpartiet
replace partyfam = 5 if prtvtse==5 | prtvtase==5 | prtvtbse==5 | prtvtcse==5 | prtvtdse==5  //moderaterna
replace partyfam = 2 if prtvtse==6 | prtvtase==6 | prtvtbse==6 | prtvtcse==6 | prtvtdse==6  //socialdemokraterna
replace partyfam = 1 if prtvtse==7 | prtvtase==7 | prtvtbse==7 | prtvtcse==7 | prtvtdse==8 //vänsterpartiet
replace partyfam = 10 if prtvtase==8 | prtvtbse==8 | prtvtcse==8 //FI
replace partyfam = 10 if prtvtase==9 | prtvtbse==9 | prtvtcse==9 //junilistan/piratpartiet
replace partyfam = 7 if prtvtase==10 | prtvtbse==10 | prtvtcse==10 | prtvtdse==7 //sverigedemokraterna

*UK* -- UKIP classified as Special Issue Party by Manifest Project - here classified as Nationalist/PRR*
replace partyfam = 5 if prtvtgb==1 | prtvtagb==1 | prtvtbgb==1 | prtvtcgb==1  //Conservative Party
replace partyfam = 2 if prtvtgb==2 | prtvtagb==2 | prtvtbgb==2 | prtvtcgb==2  //Labour
replace partyfam = 3 if prtvtgb==3 | prtvtagb==3 | prtvtbgb==3 | prtvtcgb==3  //Liberal Democrats
replace partyfam = 9 if prtvtgb==4 | prtvtagb==4 | prtvtbgb==4 | prtvtcgb==4  //Scottish National Party
replace partyfam = 9 if prtvtgb==5 | prtvtagb==5 | prtvtbgb==5 | prtvtcgb==5   //Plaid Cymru
replace partyfam = 8 if prtvtgb==6 | prtvtagb==6 | prtvtbgb==6 | prtvtcgb==6  //Green Party
replace partyfam = 7 if prtvtagb==7 | prtvtbgb==7 | prtvtcgb==7  //UKIP - classified as Nationalist

*Bulgaria*
replace partyfam = 1 if prtvtbg==1 | prtvtabg==1 | prtvtbbg==2 | prtvtcbg==2 | prtvtdbg==2 | prtvtebg==2 | prtvtebg==2 |prtvtfbg==2 //BSP
replace partyfam = 9 if prtvtbg==2 | prtvtabg==2 | prtvtbbg==3 | prtvtdbg==4 | prtvtebg==3 | prtvtebg==3 |prtvtfbg==3 //DPS
replace partyfam = 3 if prtvtbg==4 | prtvtabg==4 | prtvtbbg==4 //DSB
replace partyfam = 3 if prtvtbg==5 | prtvtabg==5 | prtvtbbg==7 //NDSV
replace partyfam = 3 if prtvtbg==6  //SDS
replace partyfam = 6 if prtvtbg==7 | prtvtabg==7 //BNS
replace partyfam = 7 if prtvtbg==10 | prtvtabg==10 | prtvtbbg==5 | prtvtcbg==3 | prtvtdbg==3 | prtvtebg==8 //Ataka
replace partyfam = 3 if prtvtabg==6 | prtvtcbg==8 //ODS
replace partyfam = 4 if prtvtbbg==1 | prtvtcbg==1 | prtvtdbg==1 | prtvtebg==1 | prtvtebg==1 |prtvtfbg==1 //GERB
replace partyfam = 5 if prtvtbbg==6 | prtvtcbg==4 //RZS
replace partyfam = 7 if prtvtcbg==5 | prtvtebg==5 | prtvtebg==5 //VMRO
replace partyfam = 7 if prtvtcbg==7  //NFSB 
replace partyfam = 7 if prtvtdbg==5 //Volya
replace partyfam = 3 if prtvtebg== 4 | prtvtebg==4 //Demokratichna Balgariya Democratic Bulgaria
replace partyfam = 4 if prtvtebg==5  | prtvtebg==5 | prtvtfbg==5 // ITN There Is Such a People - A bit problematic - is not included in Manifesto. Not far-right according to thepopulist.org
replace partyfam = 7 if prtvtebg==9 | prtvtebg==9 | prtvtfbg==6   //Vazrazhdane - Revival
replace partyfam = 10 if prtvtebg==10 | prtvtebg==10  //Izpravi se! Mutri van! /Stand up BG! we are coming! - anti-corruption coalition. Hard to classify. 
replace partyfam = 3 if prtvtfbg==4  //(PP-DB)

*Czechia*
replace partyfam = 2 if prtvtcz==1 | prtvtacz==2 | prtvtbcz==2 | prtvtccz==2 | prtvtdcz==2 | prtvtecz==2 //CSSD
replace partyfam = 5 if prtvtcz==8 | prtvtacz==5 | prtvtbcz==7 | prtvtccz==5 | prtvtdcz==5 | prtvtecz==5 //ODS
replace partyfam = 1 if prtvtcz==9 | prtvtacz==1 | prtvtbcz==1 | prtvtccz==1 | prtvtdcz==1 | prtvtecz==1 //KSČM
replace partyfam = 5 if prtvtcz==10 | prtvtbcz==5 | prtvtdcz==6 | prtvtecz==6 // Koalice (Christian Dem.&Freedom Union)KDU-ČSL-US-DEU
replace partyfam = 8 if prtvtcz==13 | prtvtacz==3 | prtvtbcz==3 //Green Party SZ
replace partyfam = 4 if prtvtacz==4  //KDU-CSL
replace partyfam = 4 if prtvtbcz==5 | prtvtccz==3 | prtvtdcz==3 | prtvtecz==3  //TOP 09
replace partyfam = 9 if prtvtbcz==6 | prtvtccz==4  //VV
replace partyfam = 3 if prtvtdcz==4 | prtvtecz==4 //ANO 2011
replace partyfam = 7 if prtvtdcz==7  //Usvit - Dawn
replace partyfam = 10 if prtvtecz==7  //Pirate Party
replace partyfam = 7 if prtvtecz==8 //Freedom and Direct Democracy
replace partyfam = 5 if prtvtecz==9 //Mayors and Independents

*Estonia*
replace partyfam = 5 if prtvtee==1 | prtvtaee==1 | prtvtbee==1 | prtvtcee==1 | prtvtdee==1 | prtvteee==3 | prtvtfee==3 | prtvtgee==3 | prtvthee==3 //Res Publica
replace partyfam = 3 if prtvtee==2 | prtvtaee==2 | prtvtbee==2 | prtvtcee==2 | prtvtdee==2 | prtvteee==2 | prtvtfee==2 | prtvtgee==2 | prtvthee==2 //Estonian Centre Party  Eesti Keskerakond
replace partyfam = 3 if prtvtee==3 | prtvtaee==3 | prtvtbee==3 | prtvtcee==3 | prtvtdee==3 | prtvteee==1 | prtvtfee==1 | prtvtgee==1 | prtvthee==1 //Reform party  Eesti Reformierakond
replace partyfam = 5 if prtvtee==4 | prtvtaee==4 //Pro Patria Isamaaliit
replace partyfam = 2 if prtvtee==5 | prtvtaee==5 | prtvtbee==5 | prtvtcee==5 | prtvtdee==5 | prtvteee==4 | prtvtfee==4 | prtvtgee==4 | prtvthee==4 //Social Democratic Party Sotsiaaldemokraatlik Erakond
replace partyfam = 6 if prtvtee==6 | prtvtaee==6 | prtvtbee==4 | prtvtcee==4 // Eestimaa Rahvaliit Estonian People's Union
replace partyfam = 8 if prtvtbee==6 | prtvtcee==6 | prtvtdee==6 | prtvteee==5 | prtvtfee==5 | prtvtgee==5 | prtvthee==5 //Erakond Eestimaa Rohelised Estonian Greens
replace partyfam = 7 if prtvteee==6 | prtvtfee==6 | prtvtgee==6  | prtvthee==6 //EKRE Eesti Konservatiivne Rahvaerakond
replace partyfam = 5 if prtvtfee==11 | prtvtgee==11 | prtvthee==11  //Free Party Eesti Vabaerakond

*Hungary*
replace partyfam = 5 if prtvthu==2 | prtvtahu==4 | prtvtbhu==4 | prtvtchu==4 //FYD-HDF MSzDP
replace partyfam = 1 if prtvthu==5 | prtvtdhu==8 | prtvtdhu==8 | prtvtehu==4 | prtvtfhu==7 | prtvtghu==7 //HSP Hungarian Socialist Party  MSZP
replace partyfam = 3 if prtvthu==7 | prtvtahu==6 | prtvtbhu==6 | prtvtchu==6 // FFD-Free Democrats SzDSz
replace partyfam = 5 if prtvtahu==1 | prtvtbhu==1 | prtvtehu==1 //Fidesz pre-2010
replace partyfam = 4 if prtvtahu==2 | prtvtbhu==2 | prtvtchu==2 //MDF
replace partyfam = 7 if prtvtchu==1 | prtvtdhu==3 | prtvtfhu==3 | prtvtghu==3 | prtvthhu==6  //Fidesz post 2010 PRR
replace partyfam = 7 if prtvtchu==11 | prtvtdhu==4 | prtvtehu==2 | prtvtfhu==4 | prtvtghu==4 //Jobbik
replace partyfam = 8 if prtvtchu==13 | prtvtdhu==5 | prtvtehu==3 | prtvtfhu==6 | prtvtghu==6 //Lehet Mas a Politika (LMP) Green Party
replace partyfam = 2 if prtvtfhu==1 | prtvtghu==1 // DK (Demokratikus Koalíció) Democratic Coalition
replace partyfam = 5 if prtvtfhu==5  //KDNP
replace partyfam = 3 if prtvtghu==9  //Momentum Mozgalom / Momentum Movement
replace partyfam = 3 if prtvthhu==1  //Ellenzéki Összefogás United for Hungary - difficult to classify - tent opposition to Fidesz
replace partyfam = 7 if prtvthhu==5  //Mi Hazank Our Homeland Movement

*Poland*
replace partyfam = 2 if prtvtpl==1  //Coalion of the Democratic Left Alliance and the Union of Labour - Sojusz Lewicy Demokratycznej/Unia Pracy
replace partyfam = 5 if prtvtpl==2  //Akcja Wyborcza Solidarność Prawicy - Solidarity Electoral Action
replace partyfam = 3 if prtvtpl==3  //Unia Wolności - Freedom Union
replace partyfam = 6 if prtvtpl==4 | prtvtbpl==7  //Self-Defence of the Polish Republic - Samoobrona Rzeczypospolitej Polskiej
replace partyfam = 7 if prtvtpl==5 | prtvtapl==14 | prtvtbpl==6 | prtvtcpl==6  //Law and Justice - Prawo i Sprawiedliwość
replace partyfam = 6 if prtvtpl==6 | prtvtapl==13 | prtvtbpl==5 | prtvtcpl==5 | prtvtdpl==5 | prtvtepl==4 //Polish Peasants' Party - Polskie Stronnictwo Ludowe 
replace partyfam = 3 if prtvtpl==7 | prtvtapl==9 | prtvtbpl==3 | prtvtcpl==2 | prtvtdpl==4  //Civic Platform - Platforma Obywatelska
replace partyfam = 4 if prtvtpl==10 | prtvtapl==3 | prtvtbpl==2  //League of Polish Families - Liga Polskich Rodzin 
replace partyfam = 2 if prtvtapl==18 | prtvtcpl==8 | prtvtepl==6  //Democratic Left Alliance - Sojusz Lewicy Demokratycznej
replace partyfam = 2 if prtvtbpl==1  //Left and Democrats - Lewica i Demokraci 
replace partyfam = 3 if prtvtcpl==7  //Palikot's Movement - Ruch Palikot
replace partyfam = 7 if prtvtdpl==2  //Kukiz'15
replace partyfam = 3 if prtvtdpl==3  //Modern - Nowoczesna
replace partyfam = 1 if prtvtdpl==8  //United Left - Zjednoczona Lewica
replace partyfam = 7 if prtvtdpl==6 | prtvtepl==5 | prtvtfpl==2  //Law and Justice - Prawo i Sprawiedliwość 

replace partyfam = 3 if prtvtepl==2 | prtvtfpl==1 //Civic Coalition - Koalicja Obywatelska
replace partyfam = 7 if prtvtepl==3 | prtvtfpl==5  //Confederation Liberty and Independence - Konfederacja Wolność i Niepodległość
replace partyfam = 4 if prtvtfpl==3  //Trzecia Droga - Third Way (Not in Manifesto, here classified as Christian Democrat)
replace partyfam = 2 if prtvtfpl==4  //Nowa Lewica - New Left

*Slovenia*
replace partyfam = 10 if prtvtsi==1 | prtvtasi==7 | prtvtbsi==1 | prtvtcsi==1 | prtvtdsi==1 | prtvtesi==1 | prtvtfsi==1 | prtvtgsi==1 //DESUS
replace partyfam = 3 if prtvtsi==2 | prtvtasi==2 | prtvtbsi==2 | prtvtcsi==2 | prtvtdsi==2 //LDS - Liberal Democracy of Slovenia - Liberalna demokracija Slovenije
replace partyfam = 4 if prtvtsi==3 | prtvtasi==5 | prtvtbsi==3 | prtvtcsi==6 | prtvtdsi==5 | prtvtesi==7 | prtvtfsi==9 //SLS - Slovenian Liberal Party - Slovenska Ljudska Stranka
replace partyfam = 7 if prtvtsi==4 | prtvtasi==6 | prtvtbsi==4 | prtvtcsi==7 | prtvtdsi==10 | prtvtfsi==11  | prtvtgsi==9 //SNS - Slovenian National Party - Slovenska nacionalna stranka
replace partyfam = 5 if prtvtsi==5 | prtvtasi==1 | prtvtbsi==5 | prtvtcsi==5 | prtvtdsi==4 | prtvtesi==6 //SDS - Slovenian Democratic Party - Socialdemokratska Stranka Slovenije
replace partyfam = 7 if prtvtfsi==8 | prtvtgsi==8 //SDS PRR from 2015 (The Populist)
replace partyfam = 7 if prtvtsi==6 | prtvtasi==4 | prtvtbsi==6 | prtvtcsi==4 | prtvtdsi==3 | prtvtesi==3 | prtvtgsi==6  //NSI - New Slovenian Christian People's Party - Nova Slovenija – Kršcanski demokrati
replace partyfam = 2 if prtvtsi==7 | prtvtasi==3  // ZLSD - Associated List of Social Democrats - Združena lista socialnih demokratov
replace partyfam = 10 if prtvtsi==8  //SMS - Party of Slovenian Youth - Stranka Mladih Slovenije
replace partyfam = 2 if prtvtbsi==7 | prtvtcsi==8 | prtvtdsi==6 | prtvtesi==5 | prtvtfsi==6 | prtvtgsi==10  //SD - Social Democratic Party - Socialni demokrati
replace partyfam = 3 if prtvtcsi==9 | prtvtdsi==9  //Zares
replace partyfam = 2 if prtvtdsi==7 | prtvtesi==4 | prtvtfsi==5  //PS - Positive Slovenia
replace partyfam = 3 if prtvtdsi==8 | prtvtesi==2  //DL - Državljanska lista
replace partyfam = 3 if prtvtdsi==8 | prtvtfsi==10 //SMC - Modern Centre Party - Stranka Mira Cerarja
replace partyfam = 3 if prtvtdsi==10 | prtvtfsi==7 | prtvtgsi==11  //ZaAB - Party of Alenka Bratušek
replace partyfam = 1 if prtvtdsi==11 | prtvtfsi==2 | prtvtgsi==4 //L - United Left - Združena levica
replace partyfam = 3 if prtvtfsi==3 | prtvtgsi==5  //LMŠ - Lista Marjana Šarca - 
replace partyfam = 3 if prtvtgsi==3  //Gibanje svoboda - Freedom Movement

*Slovakia*
replace partyfam = 7 if prtvtsk==1 | prtvtask==1  //HZDS - Movement for a Democratic Slovakia 
replace partyfam = 4 if prtvtsk==2 | prtvtask==2 | prtvtbsk==2 | prtvtcsk==2  //SDKU - Slovak Democratic Christian Union
replace partyfam = 2 if prtvtsk==3 | prtvtask==3 | prtvtbsk==3 | prtvtcsk==3 | prtvtdsk==3 | prtvtesk==2  //SMER
replace partyfam = 9 if prtvtsk==4 | prtvtask==4   //SMK - Party of Hungarian Coalition
replace partyfam = 4 if prtvtsk==5 | prtvtask==5 | prtvtbsk==5 | prtvtcsk==5  //KDH - Christian Democratic Movement
replace partyfam = 3 if prtvtsk==6  // ANO New Citizen's Alliance
replace partyfam = 1 if prtvtsk==7  //KSS Communist Party of Slovakia
replace partyfam = 7 if prtvtask==6 | prtvtbsk==1 | prtvtdsk==2  //SNS - Slovak National Party 

replace partyfam = 10 if prtvtbsk==4 | prtvtcsk==4 | prtvtdsk==4 //Most-Hid - Bridge 
replace partyfam = 3 if prtvtbsk==6 | prtvtcsk==6 | prtvtdsk==6 | prtvtesk==6  // SaS - Freedom and Solidarity 
replace partyfam = 5 if prtvtcsk==1 | prtvtdsk==1 | prtvtesk==1  //OLaNO - Ordinary People and Independent Personalities 
replace partyfam = 7 if prtvtdsk==5  | prtvtesk==4 //ĽSNS - Kotleba – People's Party Our Slovakia
replace partyfam = 5 if prtvtdsk==7  //Network - Sieť
replace partyfam = 7 if prtvtdsk==8 | prtvtesk==3  //We Are Family - SME Rodina
replace partyfam = 3 if prtvtesk==5  //Progressive Slovakia - spolu
replace partyfam = 3 if prtvtesk==7  //Za ľudí 

label variable partyfam "Party family"

label define partyfam 1 "Socialist/Communist" 2 "Social democratic" 3 "Liberal" 4 "Christian democratic" 5 "Conservative" 6 "Agrarian" 7 "Nationalist" 8 "Ecological/Green" 9 "Ethnic and regional" 10 "Special issue parties", replace 

label values partyfam partyfam


**Electoral winners and losers**

*Date variables*
replace inwyys = inwyr if essround<3
replace inwmms = inwmm if essround<3
replace inwdds = inwdd if essround<3
gen date = inwyys*10000 + inwmms * 100 +  inwdds

**Austria**
recode prtvtat (2 3=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_at1)
recode prtvtat (2 3=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_at2a)
recode prtvtat (2 6=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_at2b)
replace winlose_at2a=. if date<20050405
replace winlose_at2b=. if date>=20050405
recode prtvtaat (1 2=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_at3)
recode prtvtbat (1 2=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_at7)
recode prtvtbat (1 2=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_at8)
recode prtvtcat (2 3=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_at9)
recode prtvtcat (2 5 =1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_at10)
recode prtvtdat (2 5 =1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_at11)


**Bulgaria**
recode prtvtbg (1 2 5=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_bg3)
recode prtvtabg (1 2 5=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_bg4)
recode prtvtbbg (1=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_bg5)
recode prtvtcbg (1=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_bg6a)
recode prtvtcbg (13=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_bg6b)
**Unsure about coding here - government seems to be party-independent so this is coded 13 "candidates raised by the initiative committees", according to Google Translate** 
replace winlose_bg6a=. if date<20081210
replace winlose_bg6b=. if date>=20081210
recode prtvtdbg (1 3=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_bg9)
*ROUND 10: There were elections in April and July 2021 but no government was formed until after the November 2021 election - after the fieldwork of round 10. Thus, the following refers to the 2017 goverment. At the time of fieldwork for round 10 there was a caretaker government.
recode prtvtebg  (66/max=.) (nonmissing=0) if essround==10, gen(winlose_bg10)

**Denmark**
recode prtvtdk (3 8=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_dk1)
recode prtvtdk (3 8=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_dk2)
recode prtvtadk (3 8=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_dk3)
recode prtvtbdk (3 7=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_dk4)
recode prtvtbdk (3 7=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_dk5)
recode prtvtcdk (1 2 4=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_dk6)
recode prtvtcdk (1 2=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_dk7)
recode prtvtddk (3 7 8=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_dk9)

**Estonia**
recode prtvtee (1 3 6=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_ee2)
recode prtvtaee (2 3 6=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_ee3a)
recode prtvtaee (1 3 4 5=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_ee3b)
replace winlose_ee3a=. if date<20070405
replace winlose_ee3b=. if date>=20070405
recode prtvtbee (1 3 5=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_ee4)
recode prtvtcee (1 3=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_ee5)
recode prtvtdee (1 3=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_ee6)
recode prtvteee (1 4=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_ee7)
recode prtvtfee (1 3 4=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_ee8a)
recode prtvtfee (2 3 4=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_ee8b)
replace winlose_ee8a=. if inwyr < 16 & inwmm < 11 & inwdd < 20
replace winlose_ee8b=. if inwyr > 16 & inwmm > 11 & inwdd > 20
recode prtvtgee (2 3 4=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_ee9)
recode prtvthee (1 2=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_ee10)

**Finland**
recode prtvtfi (1 2 9 10=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_fi1)
recode prtvtfi (2 4 9=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_fi2)
recode prtvtfi (2 4 9=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_fi3)
recode prtvtafi (1 2 4 7=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_fi4)
recode prtvtbfi (1 2 4 13=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_fi5)
recode prtvtcfi (1 2 5 12 13 14=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_fi6)
recode prtvtcfi (1 2 5 13=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_fi7)
recode prtvtdfi (1 3 4=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_fi8)
recode prtvtdfi (1 3 16=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_fi9)
recode prtvtefi (2 3 16 17 18=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_fi10)
recode prtvtffi (3 4 5 8 =1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_fi11)

**Hungary**
recode prtvthu (5 7=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_hu1)
recode prtvthu (5 7=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_hu2)
recode prtvtahu (4 6=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_hu3)
recode prtvtbhu (4=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_hu4a)
recode prtvtbhu (4 16=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_hu4b)
replace winlose_hu4a=. if date<20090414
replace winlose_hu4b=. if date>=20090414
recode prtvtchu (1=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_hu5)
recode prtvtdhu (3=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_hu6)
recode prtvtehu (1=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_hu7)
recode prtvtehu (1=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_hu8)
recode prtvtfhu (3 5=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_hu9)
recode prtvtghu (3 5=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_hu10)
recode prtvthhu (6=1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_hu11)

**Italy - many "other" here**
recode prtvtit (8 9 10 11=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_it1)
recode prtvtait (8 9 11 12 17=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_it2a)
recode prtvtait (3 4 7 17 19=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_it2b)
replace winlose_it2a=. if date<20060517
replace winlose_it2b=. if date>=20060517
recode prtvtbit (1 5 8 6 11=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_it6a)
recode prtvtbit (1 5 6 11 17=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_it6b)
replace winlose_it6a=. if date<20131118
replace winlose_it6b=. if date>= 20131118
recode prtvtbit (1 6 17=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_it8)
recode prtvtcit (7 8 14=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_it9)
recode prtvtdit (3 4 5=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_it10)
recode prtvteit (1 4 5=1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_it11)

**Netherlands**
recode prtvtnl (1 3 4=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_nl1)
recode prtvtanl (1 3 5=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_nl2)
recode prtvtbnl (1 3=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_nl3a)
recode prtvtbnl (1 2 8=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_nl3b)
replace winlose_nl3a=. if date<20070222
replace winlose_nl3b=. if date>=20070222
recode prtvtcnl (1 2 8=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_nl4)
recode prtvtdnl (4 8=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_nl5a)
recode prtvtdnl (1 4=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_nl5b)
replace winlose_nl5a=. if date<20101014
replace winlose_nl5b=. if date>=20101014
recode prtvtenl (1 4=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_nl6a)
recode prtvtenl (1 2=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_nl6b)
replace winlose_nl6a=. if date<20121105
replace winlose_nl6b=. if date>=20121105
recode prtvtfnl (1 2=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_nl7)
recode prtvtfnl (1 2=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_nl8)
recode prtvtgnl (1 5 6 7=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_nl9)
recode prtvthnl (1 5 6 7=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_nl10)
recode prtvtinl (1 5 6 7=1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_nl11)

**Norway*
recode prtvtno (4 5 7=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_no1)
recode prtvtno (4 5 7=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_no2)
recode prtvtno (2 3 6=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_no3)
recode prtvtno (2 3 6=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_no4)
recode prtvtano (2 3 6=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_no5)
recode prtvtano (2 3 6=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_no6)
recode prtvtbno (7 8=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_no7)
recode prtvtbno (7 8=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_no8)
recode prtvtbno (4 7 8=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_no9a)
recode prtvtbno (4 5 7 8=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_no9b)
replace winlose_no9a=. if date<20190122
replace winlose_no9b=. if date>=20190122 
gen double cutoff = clock("14oct2021 00:00:00", "DMYhms")
gen after_oct14 = inwds >= cutoff
recode prtvtbno (4 5 7=1) (66/max=.) (nonmissing=0) if essround==10 & after_oct14==0, gen(winlose_no10a)
recode prtvtbno (3 6=1) (66/max=.) (nonmissing=0) if essround==10 & after_oct14==1, gen(winlose_no10b)
recode prtvtcno (3 6=1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_no11)

**Poland**
recode prtvtpl (1 6=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_pl1)
recode prtvtpl (1 6=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_pl2)
recode prtvtapl (3 14 16=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_pl3)
recode prtvtbpl (3 5=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_pl4)
recode prtvtbpl (3 5=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_pl5)
recode prtvtcpl (2 5=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_pl6)
recode prtvtcpl (2 5=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_pl7)
recode prtvtdpl (6=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_pl8)
recode prtvtdpl (6=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_pl9)
recode prtvtepl (5=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_pl10)

gen double cutoff1 = clock("13dec2023 00:00:00", "DMYhms")
gen after_dec13 = inwds >= cutoff1

recode prtvtfpl (2=1) (66/max=.) (nonmissing=0) if essround==11 & after_dec==0, gen(winlose_pl11a)
recode prtvtfpl (1 4=1) (66/max=.) (nonmissing=0) if essround==11 & after_dec==1, gen(winlose_pl11b)

**Slovakia**
recode prtvtsk (2 4 6=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_sk2)
recode prtvtask (1 3 6=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_sk3)
recode prtvtask (1 3 6=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_sk4)
recode prtvtbsk (2 4 5 6=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_sk5)
recode prtvtcsk (3=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_sk6)
recode prtvtdsk (2 3 4=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_sk9)
recode prtvtesk (1 3 6 7=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_sk10)

gen double cutoff2 = clock("25oct2023 00:00:00", "DMYhms")
gen after_oct25 = inwds >= cutoff2

recode prtvtesk (1/8=0) (66/max=.) (nonmissing=0) if essround==11 & after_oct25==0, gen(winlose_sk11a)
recode prtvtesk (2=1) (66/max=.) (nonmissing=0) if essround==11 & after_oct25==1, gen(winlose_sk11b)

**Slovenia**
recode prtvtsi (2 3 7=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_si1)
recode prtvtasi (2 3 7=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_si2)
recode prtvtbsi (1 3 5 6=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_si3)
recode prtvtcsi (1 4 5 6=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_si4a)
recode prtvtcsi (1 2 8 9=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_si4b)
replace winlose_si4a=. if date<20081121
replace winlose_si4b=. if date>=20081121
recode prtvtcsi (1 2 8 9=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_si5)
recode prtvtdsi (1 3 4 5 8=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_si6)
recode prtvtesi (1 5 8=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_si7)
recode prtvtesi (1 5 8=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_si8)
recode prtvtfsi (1 3 5 6 10=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_si9)
recode prtvtfsi (4 8 10=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_si10)
recode prtvtgsi (3 4 10=1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_si11)

**Sweden**
recode prtvtse (6=1) (66/max=.) (nonmissing=0) if essround==1, gen(winlose_se1)
recode prtvtse (6=1) (66/max=.) (nonmissing=0) if essround==2, gen(winlose_se2)
recode prtvtse (6=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_se3a)
recode prtvtse (1 2 3 5=1) (66/max=.) (nonmissing=0) if essround==3, gen(winlose_se3b)
replace winlose_se3a=. if date<20061005
replace winlose_se3b=. if date>=20061005
recode prtvtse (1 2 3 5=1) (66/max=.) (nonmissing=0) if essround==4, gen(winlose_se4)
recode prtvtase (1 2 3 5=1) (66/max=.) (nonmissing=0) if essround==5, gen(winlose_se5)
recode prtvtbse (1 2 3 5=1) (66/max=.) (nonmissing=0) if essround==6, gen(winlose_se6)
recode prtvtbse (1 3 2 5=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_se7a)
recode prtvtbse (4 6=1) (66/max=.) (nonmissing=0) if essround==7, gen(winlose_se7b)
replace winlose_se7a=. if date<20141003
replace winlose_se7b=. if date>=20141003
recode prtvtbse (4 6=1) (66/max=.) (nonmissing=0) if essround==8, gen(winlose_se8)
recode prtvtcse (4 6=1) (66/max=.) (nonmissing=0) if essround==9, gen(winlose_se9)
replace winlose_se9=. if date<20190120
recode prtvtdse (4 6=1) (66/max=.) (nonmissing=0) if essround==10, gen(winlose_se10)
recode prtvtdse (2 3 5=1) (66/max=.) (nonmissing=0) if essround==11, gen(winlose_se11)

egen winlose = rowmean(winlose_*)
replace winlose = 1 if winlose > 0 & winlose<1
